


**** following is how to clean recs to crecs data 

clear
use recs_1990

destring moneypy,replace
gen income=1 if moneypy<=15
replace income=2 if moneypy>15 & moneypy<=22
replace income=3 if moneypy>22
tostring income,replace
encode income, gen(hh_income)



destring yearmade,replace
recode yearmade 1/2=1 3=2 4=3 5=4 6/10=5 11/12=6, gen(hh_yearmade)

tab stories
replace stories=6 if stories>=8


gen male=(hhsex==2)
gen white=(origin==1)
gen own=(kownrent==1)


tab bedrooms 
sum heated 
tab swimpool
sum hdd65
sum cdd65
gen conservation=(consepgm==1)
gen over65=(hhage>65)

*keep kwh hh_income own region hh_typehome famsize hhage male white hh_yearmade stories ///
*homearea bedrooms heated swimpool hdd65 cdd65 conservation 

gen year=1990

save crecs_1990,replace
*** 1993
clear
use recs_1993

destring moneypy,replace
gen income=1 if moneypy<=13
replace income=2 if moneypy>13& moneypy<=20
replace income=3 if moneypy>20
tostring income,replace
encode income, gen(hh_income)


gen own=(kownrent==1)

tab stories
replace stories=6 if stories>=8


destring yearmade,replace
recode yearmade 1/2=1 3=2 4=3 5=4 6/10=5 11/15=6, gen(hh_yearmade)

gen male=(hhsex==2)
gen white=(origin==1)


ren  nhsldmem famsize

tab bedrooms 
sum heated 
tab swimpool
sum hdd65
sum cdd65
gen conservation=(consepgm==1)

gen over65=(nyr6595>0)


*keep kwh hh_income own region hh_typehome famsize hhage male white hh_yearmade stories ///
*homearea bedrooms heated swimpool hdd65 cdd65 conservation over65
gen year=1993
save crecs_1993,replace


** 1997
clear
use recs_1997

destring moneypy,replace
gen income=1 if moneypy<=13
replace income=2 if moneypy>13& moneypy<=20
replace income=3 if moneypy>20
tostring income,replace
encode income, gen(hh_income)


gen own=(kownrent==1)
replace stories=6 if stories>=8


tab yearmade 

gen male=(hhsex==2)
gen white=(origin==1)

destring yearmade,replace
recode yearmade 1/2=1 3=2 4=3 5/6=4 7/8=5 9/16=6, gen(hh_yearmade)
ren  nhsldmem famsize


rename sqftreg homearea

tab bedrooms 
rename sqftest heated
sum heated 
tab swimpool
sum hdd65
sum cdd65

gen over65=(hhage>65)
gen year=1997
save crecs_1997,replace


** 2001
clear
use recs_2001

destring moneypy,replace
gen income=1 if moneypy<=4
replace income=2 if moneypy>4& moneypy<=7
replace income=3 if moneypy>7
tostring income,replace
encode income, gen(hh_income)



gen own=(kownrent==1)
recode stories 10=1 20=2 31=3 32=4 40=5 50/99=6,gen(h_stories)

drop stories
ren h_stories stories


tab yearmade 

gen male=(hhsex==2)
gen white=(origin1==1)

destring yearmade,replace
recode yearmade 1/2=1 3=2 4=3 5=4 6/7=5 8/11=6 12/13=7, gen(hh_yearmade)
ren  nhsldmem famsize


ren totsqft homearea

tab bedrooms 
rename sqftest heated
sum heated 
tab swimpool
sum hdd65
sum cdd65

gen over65=(hhage>65)


gen year=2001
save crecs_2001,replace
** 2005
clear
use recs_2005

destring moneypy,replace
gen income=1 if moneypy<=6
replace income=2 if moneypy>6& moneypy<=10
replace income=3 if moneypy>10
tostring income,replace
encode income, gen(hh_income)


gen own=(kownrent==1)


tab yearmade 
gen male=(hhsex==2)
gen white=(origin1==1)
ren  nhsldmem famsize

destring yearmade,replace
recode yearmade 1/2=1 3=2 4=3 5=4 6/7=5 8/9=6 10/13=7, gen(hh_yearmade)

recode stories 10=1 20=2 31=3 32=4 40=5 50/99=6,gen(h_stories)
drop stories
ren h_stories stories



ren totsqft homearea
tab bedrooms 
rename sqftest heated
sum heated 
tab swimpool
sum hd65
sum cd65
ren hd65 hdd65

gen over65=0
forval i=1/12 { 
replace agehhmem`i'=-1 if agehhmem`i'==99
replace over65=1 if agehhmem`i'>=65
}


ren cd65 cdd65

gen year=2005
save crecs_2005,replace

** 2009

clear
use recs_2009

destring moneypy,replace
gen income=1 if moneypy<=6
replace income=2 if moneypy>6& moneypy<=10
replace income=3 if moneypy>10
tostring income,replace
encode income, gen(hh_income)


gen own=(kownrent==1)


tab yearmade 
gen male=(hhsex==2)
gen white=(householder_race==1)
ren  nhsldmem famsize

replace yearmaderange=7 if yearmaderange>=7
tostring yearmaderange,replace
encode yearmaderange,gen(hh_yearmade)


recode stories 10=1 20=2 31=3 32=4 40=5 -2=6,gen(h_stories)
drop stories
ren h_stories stories
*tostring h_stories,replace
*encode h_stories,gen(hh_stories)

ren totsqft homearea
tab bedrooms 
rename tothsqft heated
sum heated 
tab swimpool


gen year=2009
replace division=8 if division==9
replace division=9 if division==10

gen over65=(hhage>65)
forval i=2/14 { 
replace over65=1 if agehhmemcat`i'>=14
}



save crecs_2009,replace

**===2015

clear
use recs_2015

destring moneypy,replace
gen income=1 if moneypy<=1
replace income=2 if moneypy>1& moneypy<=2
replace income=3 if moneypy>2
tostring income,replace
encode income, gen(hh_income)

gen own=(kownrent==1)
tab yearmade 

gen male=(hhsex==2)
gen white=(householder_race==1)

recode stories 10=1 20=2 31=3 32=4 40=5 -2=6,gen(h_stories)
drop stories
ren h_stories stories


tostring yearmaderange,replace
encode yearmaderange,gen(hh_yearmade)

ren  nhsldmem famsize

tab bedrooms 
rename tothsqft heated
sum heated 
tab swimpool
sum hdd65
sum cdd65

rename  totsqft_en homearea
gen year=2015
replace division=8 if division==9
replace division=9 if division==10

gen over65=(hhage>65)

save crecs_2015,replace



